<?php

/**
 * @copyright since 0:35 5/4/2020
 * @author <mc@dancis.info>
 */

require '../vendor/autoload.php';

function get_fee($fee_rate_in_cent, $power)
{
    $power_year = $power / 1000 * 24 * 365.25;
    $power_mo = $power_year / 12;

    $fee = [
        $power_year * ($fee_rate_in_cent / 100),
        $power_mo * ($fee_rate_in_cent / 100),
    ];

    return
        'The fee is ' . $fee[1] . ' CNY per month while ' . $power_mo
        . ' kWh is used and is ' . $fee[0] . ' CNY per year while ' . $power_year . ' kWh is used.';
}

(function () {
    try {
        $power = input('Enter the power consumption in W(att) RMS (average): ');
    } catch (RuntimeException $exception) {
        exit($exception);
    }

    disp(get_fee(62, $power));
})();
